package npcSystem.mainCharSystem;

import java.io.IOException;
import java.net.URL;

import javax.sound.sampled.*;

public enum MainCharSounds {
	attack("/sound/attack.wav"),
	eat("/sound/eat.wav"),
	beingHit("/sound/hitted.wav");
	
	private Clip clip;
	
	private MainCharSounds(String filename) {
		URL is = MainCharSounds.class.getResource(filename);
		if(filename == null) 
		{
			System.out.println("arquivo "+filename+" nao encontrado");
			return;
		}
		
		try {
			AudioInputStream ai = AudioSystem.getAudioInputStream(is);
			clip = AudioSystem.getClip();
			clip.open(ai);
		} 
		catch (UnsupportedAudioFileException e) { e.printStackTrace(); } 
		catch (IOException e) { e.printStackTrace(); } 
		catch( LineUnavailableException e){ e.printStackTrace(); }
	}
	
	public void play()
	{
		if(clip.isRunning()) clip.stop();
		clip.setFramePosition(0);
		clip.start();
	}
	public static void init()
	{
		values();
	}
}
